home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / RAND / UNSPLIT / BM214SRC.ZIP / 68030 / RENDER.S < prev    next >
Encoding:
Text File  |  1996-07-01  |  40.1 KB  |  1,475 lines

  1. *=======================================================*
  2. *    Rendering module: latest update 25/03/96    *
  3. *=======================================================*
  4. *    Render walls & floors onto screenbuffer        *
  5. *=======================================================*
  6.  
  7. *-------------------------------------------------------*
  8. *    Texel addressing units [horizontal]        *
  9. *-------------------------------------------------------*
  10.  
  11. *-------------------------------------------------------*
  12. *    8-bit texel -> 16-bit pixel unit        *
  13. *-------------------------------------------------------*
  14.  
  15. hrun16    macro
  16.     move.l        d3,d0
  17.     move.w        d1,d0
  18.     lsr.l        #6,d0
  19.     lsr.w        #4,d0
  20.     move.b        (a1,d0.w),d6
  21.     add.l        d7,d3
  22.     move.w        (a0,d6.l*2),d0
  23.     add.w        d4,d1
  24.     move.w        d0,(a6)+
  25.     endm
  26.  
  27. *-------------------------------------------------------*
  28. *    8-bit texel -> 32-bit (double) pixel unit    *
  29. *-------------------------------------------------------*
  30.  
  31. hrun32s    macro
  32.     move.l        d7,a4
  33.     move.l        d3,d7
  34.     move.w        d1,d7
  35.     lsr.l        #6,d7
  36.     lsr.w        #4,d7
  37.     move.b        (a1,d7.w),d6
  38.     add.l        a4,d3
  39.     move.w        (a0,d6.l*2),d7
  40.     add.w        d4,d1
  41.     endm
  42.  
  43. hrun32    macro
  44.     move.l        d3,d0
  45.     move.w        d7,(a6)+
  46.     move.w        d1,d0
  47.     lsr.l        #6,d0
  48.     move.w        d7,(a6)+
  49.     lsr.w        #4,d0
  50.     move.b        (a1,d0.w),d6
  51.     add.l        a4,d3
  52.     move.w        (a0,d6.l*2),d7
  53.     add.w        d4,d1
  54.     endm
  55.  
  56. *-------------------------------------------------------*
  57. *    8-bit scaled -> 16-bit pixel unit        *
  58. *-------------------------------------------------------*
  59.  
  60. srun16    macro                ; 14
  61.     move.w        d3,d0
  62.     and.w        d4,d0
  63.     move.b        (a1,d0.w*8),d6
  64.     addx.l        d7,d3
  65.     move.w        (a0,d6.l*2),(a6)+
  66.     endm
  67.  
  68. *-------------------------------------------------------*
  69. *    8-bit scaled -> 32-bit (double) pixel unit    *
  70. *-------------------------------------------------------*
  71.  
  72. srun32    macro
  73.     move.w        d3,d0
  74.     and.w        d4,d0
  75.     move.b        (a1,d0.w*8),d6
  76.     addx.l        d7,d3
  77.     move.w        (a0,d6.l*2),d0
  78.     move.w        d0,(a6)+
  79.     move.w        d0,(a6)+
  80.     endm
  81.  
  82. *-------------------------------------------------------*
  83. *    Texel addressing units [vertical]        *
  84. *-------------------------------------------------------*
  85.  
  86. *-------------------------------------------------------*
  87. *    8-bit texel -> 16-bit pixel unit        *
  88. *-------------------------------------------------------*
  89.  
  90. vrun16    macro
  91.     and.w        d5,d4
  92.     move.b        (a2,d4.w),d1
  93.     addx.l        d3,d4
  94.     move.w        (a5,d1.l*2),d0
  95.     adda.l        a6,a0
  96.     move.w        d0,(a0)
  97.     endm
  98.  
  99. *-------------------------------------------------------*
  100. *    8-bit texel -> 32-bit (double) pixel unit    *
  101. *-------------------------------------------------------*
  102.  
  103. vrun32    macro
  104.     and.w        d5,d4
  105.     move.b        (a2,d4.w),d1
  106.     addx.l        d3,d4
  107.     move.w        (a5,d1.l*2),d0
  108.     adda.l        a6,a0
  109.     move.w        d0,(a0)+
  110.     move.w        d0,(a0)
  111.     endm
  112.  
  113. *-------------------------------------------------------*
  114. *    Transparent texel addressing units [vertical]    *
  115. *-------------------------------------------------------*
  116.  
  117. *-------------------------------------------------------*
  118. *    8-bit texel -> 16-bit pixel unit        *
  119. *-------------------------------------------------------*
  120.  
  121. tvrun16    macro                ; 16
  122.     and.w        d5,d4
  123.     move.b        (a2,d4.w),d1
  124.     beq.s        .tp\@
  125.     move.w        (a5,d1.l*2),(a0)
  126. .tp\@:    addx.l        d3,d4
  127.     adda.l        a6,a0
  128.     endm
  129.  
  130. *-------------------------------------------------------*
  131. *    8-bit texel -> 32-bit (double) pixel unit    *
  132. *-------------------------------------------------------*
  133.  
  134. tvrun32    macro                ; 20
  135.     and.w        d5,d4
  136.     move.b        (a2,d4.w),d1
  137.     beq.s        .tp\@
  138.     move.w        (a5,d1.l*2),d0
  139.     move.w        d0,(a0)
  140.     move.w        d0,2(a0)
  141. .tp\@:    addx.l        d3,d4
  142.     adda.l        a6,a0
  143.     endm
  144.  
  145. *-------------------------------------------------------*
  146. *    QuickAlpha texel addressing units [vertical]    *
  147. *-------------------------------------------------------*
  148.  
  149. *-------------------------------------------------------*
  150. *    8-bit texel -> 16-bit pixel unit        *
  151. *-------------------------------------------------------*
  152.  
  153. avrun16    macro                ; 10
  154.     move.w        (a0,a6.l),d1
  155.     adda.l        a6,a0
  156.     move.w        (a5,d1.l*2),(a0)
  157.     endm
  158.  
  159. *-------------------------------------------------------*
  160. *    8-bit texel -> 32-bit (double) pixel unit    *
  161. *-------------------------------------------------------*
  162.  
  163. avrun32    macro                ; 14
  164.     move.w        (a0,a6.l),d1
  165.     adda.l        a6,a0
  166.     move.w        (a5,d1.l*2),d1
  167.     move.w        d1,(a0)+
  168.     move.w        d1,(a0)+
  169.     endm
  170.  
  171. *-------------------------------------------------------*
  172. *    Render the floors & ceilings            *
  173. *-------------------------------------------------------*
  174. render_flats:
  175. *-------------------------------------------------------*
  176.     tst.b        halfrows
  177.     bne        render_flats_2x1
  178.  
  179. *-------------------------------------------------------*
  180.     txtlong
  181. *-------------------------------------------------------*
  182. render_flats_1x1:
  183. *-------------------------------------------------------*
  184.     moveq        #rotatemap_command,d0
  185.     dspwrite.l    d0
  186. *-------------------------------------------------------*
  187.     move.l        screen,.local_screen
  188.     lea        zone_space,a3
  189. *-------------------------------------------------------*
  190.     lea        DSPHost16.w,a4
  191.     lea        DSPHostStat.w,a5
  192. *-------------------------------------------------------*
  193. *    Zone loop                    *
  194. *-------------------------------------------------------*
  195. .zone_loop:
  196. *-------------------------------------------------------*
  197.     moveq        #0,d4
  198.     move.b        (a3)+,d4            ; [zone_lines]
  199.     moveq        #0,d0
  200.     subq.w        #1,d4
  201.     bmi        .last_zone
  202. *-------------------------------------------------------*
  203.     move.b        (a3)+,d0            ; [zone_texture]
  204.     cmp.w        sky_index,d0
  205.     beq        .scaled_chunk
  206. *-------------------------------------------------------*
  207. .perspected_chunk:    
  208. *-------------------------------------------------------*
  209.     bsr        cache_resource
  210.     move.l        d0,a1
  211.     move.w        (a3)+,d0            ; [zone_start]
  212.     move.l        .local_screen(pc),a2
  213.     mulu.w        scrwidth,d0
  214.     lea        (a2,d0.l*2),a2
  215. *-------------------------------------------------------*
  216. .pline_loop:
  217. *-------------------------------------------------------*
  218.     move.w        (a3)+,d2            ; [line_runs]
  219.     swap        d4
  220.     subq.w        #1,d2
  221.     bmi        .pnull_line
  222. *-------------------------------------------------------*
  223. .prun_loop:
  224. *-------------------------------------------------------*
  225.     dspwaitread.0    (a5)
  226.     move.w        (a4),d7                ; map_xi
  227.     dspwaitread.4    (a5)
  228.     move.w        (a4),d3                ; map_x
  229.     dspwaitread.4    (a5)
  230.     move.w        (a4),d4                ; map_yi
  231.     dspwaitread.4    (a5)
  232.     move.w        (a4),d1                ; map_y
  233.     dspwaitread.4    (a5)
  234.     move.w        (a4),d6                ; x1
  235. *-------------------------------------------------------*
  236. *    Render flat run                    *
  237. *-------------------------------------------------------*
  238.     lea        colourtables,a0
  239.     moveq        #0,d0
  240.     move.w        (a3)+,d0
  241.     lsl.l        #6,d3
  242.     lsl.l        #6,d7
  243.     swap        d2
  244.     move.w        (a3)+,d2
  245.     lsl.l        #8,d0
  246.     add.l        d0,d0
  247.     add.l        d0,a0
  248.     lea        (a2,d6.w*2),a6
  249.     sub.w        d6,d2
  250.     moveq        #4-1,d0
  251.     and.w        d2,d0
  252.     asr.w        #2,d2                ; dx{loop}
  253.     move.l        d0,d6                ; dx{remainder} * -11
  254.     asl.w        #2,d6
  255.     sub.w        d6,d0
  256.     add.w        d6,d6
  257.     sub.w        d6,d0
  258. *-------------------------------------------------------*
  259. *    Flat-rendering instruction tower        *
  260. *-------------------------------------------------------*
  261.     jmp        .pdx_j(pc,d0.w*2)        ; index instruction tower
  262. .pdx_l:    hrun16
  263.     hrun16
  264.     hrun16
  265.     hrun16
  266. .pdx_j:    dbra        d2,.pdx_l
  267. *-------------------------------------------------------*
  268.     swap        d2
  269.     dbra        d2,.prun_loop
  270. *-------------------------------------------------------*
  271. .pnull_line:
  272. *-------------------------------------------------------*
  273.     lea        (max_xres*2)(a2),a2
  274.     swap        d4
  275.     dbra        d4,.pline_loop
  276. *-------------------------------------------------------*
  277.     bra        .zone_loop
  278. *-------------------------------------------------------*
  279. .scaled_chunk:    
  280. *-------------------------------------------------------*
  281.     move.l        #.err,d5
  282.     move.w        current_sky,d0
  283.     bmi.s        .err
  284.     bsr        cache_resource
  285.     move.l        d0,d5
  286. *-------------------------------------------------------*
  287. .err:    move.l        skyx(pc),d7                ; sxi
  288.     lea        colourtables+63*(2*256),a0
  289.     moveq        #0,d0
  290.     move.w        (a3)+,d0            ; [zone_start]
  291.     move.l        .local_screen(pc),a2
  292.     move.l        d0,d1
  293.     mulu.w        scrwidth,d0
  294.     swap        d7
  295.     lea        (a2,d0.l*2),a2
  296. *-------------------------------------------------------*
  297. .sline_loop:
  298. *-------------------------------------------------------*
  299.     move.w        (a3)+,d2            ; [line_runs]
  300.     swap        d4
  301.     subq.w        #1,d2
  302.     bmi        .snull_line
  303. *-------------------------------------------------------*
  304. .srun_loop:
  305. *-------------------------------------------------------*
  306.     addq.l        #2,a3
  307.     lea        1(a4),a1
  308.     dspwaitread.0    (a5)
  309.     tst.b        (a1)                ; map_xi
  310.     dspwaitread.4    (a5)
  311.     tst.b        (a1)                ; map_x
  312.     dspwaitread.4    (a5)
  313.     tst.b        (a1)                ; map_yi
  314.     dspwaitread.4    (a5)
  315.     tst.b        (a1)                ; map_y    
  316.     dspwaitread.4    (a5)
  317.     move.w        (a4),d6                ; x1
  318. *-------------------------------------------------------*
  319.     moveq        #128-1,d0
  320.     and.w        d1,d0
  321.     mulu.l        skyy(pc),d0
  322.     move.l        d5,a1
  323.     clr.w        d0
  324.     swap        d0
  325.     add.l        d0,a1
  326. *-------------------------------------------------------*
  327.     moveq        #0,d3
  328.     move.w        d6,d3
  329.     swap        d7
  330.     muls.l        d7,d3
  331.     add.l        xoff(pc),d3
  332.     move.w        #%0000111111110000,d4
  333.     swap        d7
  334.     swap        d3
  335. *-------------------------------------------------------*
  336. *    Render flat run                    *
  337. *-------------------------------------------------------*
  338.     swap        d2
  339.     move.w        (a3)+,d2
  340. *-------------------------------------------------------*
  341.     lea        (a2,d6.w*2),a6
  342. *-------------------------------------------------------*
  343.     sub.w        d6,d2
  344.     moveq        #4-1,d0
  345.     and.w        d2,d0
  346.     asr.w        #2,d2                ; dx{loop}
  347. *-------------------------------------------------------*
  348.     move.l        d0,d6
  349.     lsl.w        #3,d6
  350.     sub.w        d6,d0                ; dx{remainder} * -7
  351. *-------------------------------------------------------*
  352.     move.w        d3,d6
  353.     add.l        d7,d3
  354.     move.w        d6,d3
  355.     moveq        #0,d6
  356. *-------------------------------------------------------*
  357. *    Flat-rendering instruction tower        *
  358. *-------------------------------------------------------*
  359.     jmp        .sdx_j(pc,d0.w*2)        ; index instruction tower
  360. .sdx_l:    srun16
  361.     srun16
  362.     srun16
  363.     srun16
  364. .sdx_j:    dbra        d2,.sdx_l
  365. *-------------------------------------------------------*
  366.     swap        d2
  367.     dbra        d2,.srun_loop
  368. *-------------------------------------------------------*
  369. .snull_line:
  370. *-------------------------------------------------------*
  371.     lea        (max_xres*2)(a2),a2
  372.     addq.l        #1,d1
  373.     swap        d4
  374.     dbra        d4,.sline_loop
  375. *-------------------------------------------------------*
  376.     bra        .zone_loop
  377. *-------------------------------------------------------*
  378. .last_zone:
  379. *-------------------------------------------------------*
  380. .stop:    rts
  381.     
  382. *-------------------------------------------------------*
  383. *    Local variables                    *
  384. *-------------------------------------------------------*
  385. .local_screen:        ds.l    1
  386. *-------------------------------------------------------*
  387.  
  388. *-------------------------------------------------------*
  389.     txtlong
  390. *-------------------------------------------------------*
  391. render_flats_2x1:
  392. *-------------------------------------------------------*
  393.     moveq        #rotatemap_command,d0
  394.     dspwrite.l    d0
  395. *-------------------------------------------------------*
  396.     move.l        screen,.local_screen
  397.     lea        zone_space,a3
  398. *-------------------------------------------------------*
  399.     lea        DSPHostStat.w,a5
  400. *-------------------------------------------------------*
  401. *    Zone loop                    *
  402. *-------------------------------------------------------*
  403. .zone_loop:
  404. *-------------------------------------------------------*
  405.     moveq        #0,d4
  406.     move.b        (a3)+,d4            ; [zone_lines]
  407.     moveq        #0,d0
  408.     subq.w        #1,d4
  409.     bmi        .last_zone
  410. *-------------------------------------------------------*
  411.     move.b        (a3)+,d0            ; [zone_texture]
  412.     cmp.w        sky_index,d0
  413.     beq        .scaled_chunk
  414. *-------------------------------------------------------*
  415. .perspected_chunk:
  416. *-------------------------------------------------------*
  417.     bsr        cache_resource
  418.     move.l        d0,a1
  419.     move.w        (a3)+,d0            ; [zone_start]
  420.     move.l        .local_screen(pc),a2
  421.     mulu.w        scrwidth,d0
  422.     lea        (a2,d0.l*2),a2
  423. *-------------------------------------------------------*
  424. .line_loop:
  425. *-------------------------------------------------------*
  426.     move.w        (a3)+,d2            ; [line_runs]
  427.     swap        d4
  428.     subq.w        #1,d2
  429.     bmi        .null_line
  430. *-------------------------------------------------------*
  431. .run_loop:
  432. *-------------------------------------------------------*
  433.     lea        DSPHost16.w,a4
  434.     dspwaitread.0    (a5)
  435.     move.w        (a4),d7                ; map_xi
  436.     dspwaitread.4    (a5)
  437.     move.w        (a4),d3                ; map_x
  438.     dspwaitread.4    (a5)
  439.     move.w        (a4),d4                ; map_yi
  440.     dspwaitread.4    (a5)
  441.     move.w        (a4),d1                ; map_y
  442.     dspwaitread.4    (a5)
  443.     move.w        (a4),d6                ; x1
  444. *-------------------------------------------------------*
  445. *    Render flat run                    *
  446. *-------------------------------------------------------*
  447.     lea        colourtables,a0
  448.     moveq        #0,d0
  449.     move.w        (a3)+,d0
  450.     lsl.l        #6,d3
  451.     lsl.l        #6,d7
  452.     swap        d2
  453.     move.w        (a3)+,d2
  454.     lsl.l        #8,d0
  455.     add.l        d0,d0
  456.     add.l        d0,a0
  457.     lea        (a2,d6.w*4),a6
  458.     addq.w        #1,d6
  459.     sub.w        d6,d2
  460.     moveq        #4-1,d0
  461.     and.w        d2,d0
  462.     lsr.w        #2,d2                ; dx{loop}
  463.     move.l        d0,d6
  464.     lsl.w        #2,d6
  465.     sub.w        d6,d0                ; dx{remainder} * -24
  466. *-------------------------------------------------------*
  467. *    Flat-rendering instruction tower        *
  468. *-------------------------------------------------------*
  469.     hrun32s
  470.     jmp        .dx_j(pc,d0.w*8)        ; index instruction tower
  471. .dx_l:    hrun32
  472.     hrun32
  473.     hrun32
  474.     hrun32
  475. .dx_j:    dbra        d2,.dx_l
  476.     move.w        d7,(a6)+
  477.     move.w        d7,(a6)+
  478. *-------------------------------------------------------*
  479.     swap        d2
  480.     dbra        d2,.run_loop
  481. *-------------------------------------------------------*
  482. .null_line:
  483. *-------------------------------------------------------*
  484.     lea        (max_xres*2)(a2),a2
  485.     swap        d4
  486.     dbra        d4,.line_loop
  487. *-------------------------------------------------------*
  488.     bra        .zone_loop
  489. *-------------------------------------------------------*
  490. .scaled_chunk:    
  491. *-------------------------------------------------------*
  492.     move.l        #.err,d5
  493.     move.w        current_sky,d0
  494.     bmi.s        .err
  495.     bsr        cache_resource
  496.     move.l        d0,d5
  497. *-------------------------------------------------------*
  498. .err:    move.l        skyx(pc),d7                ; sxi
  499.     lea        colourtables+63*(2*256),a0
  500.     moveq        #0,d0
  501.     move.w        (a3)+,d0            ; [zone_start]
  502.     move.l        .local_screen(pc),a2
  503.     move.l        d0,d1
  504.     mulu.w        scrwidth,d0
  505.     swap        d7
  506.     lea        (a2,d0.l*2),a2
  507. *-------------------------------------------------------*
  508. .sline_loop:
  509. *-------------------------------------------------------*
  510.     move.w        (a3)+,d2            ; [line_runs]
  511.     swap        d4
  512.     subq.w        #1,d2
  513.     bmi        .snull_line
  514. *-------------------------------------------------------*
  515. .srun_loop:
  516. *-------------------------------------------------------*
  517.     addq.l        #2,a3
  518.     lea        DSPHost16.w,a4
  519.     lea        1(a4),a1
  520.     dspwaitread.0    (a5)
  521.     tst.b        (a1)                ; map_xi
  522.     dspwaitread.4    (a5)
  523.     tst.b        (a1)                ; map_x
  524.     dspwaitread.4    (a5)
  525.     tst.b        (a1)                ; map_yi
  526.     dspwaitread.4    (a5)
  527.     tst.b        (a1)                ; map_y    
  528.     dspwaitread.4    (a5)
  529.     move.w        (a4),d6                ; x1
  530. *-------------------------------------------------------*
  531.     move.l        skyy(pc),d0
  532.     move.l        d5,a1
  533.     mulu.l        d1,d0
  534.     clr.w        d0
  535.     swap        d0
  536.     add.l        d0,a1
  537. *-------------------------------------------------------*
  538.     moveq        #0,d3
  539.     move.w        d6,d3
  540.     swap        d7
  541.     mulu.l        d7,d3
  542.     add.l        xoff(pc),d3
  543.     move.w        #%0000111111110000,d4
  544.     swap        d7
  545.     swap        d3
  546. *-------------------------------------------------------*
  547. *    Render flat run                    *
  548. *-------------------------------------------------------*
  549.     swap        d2
  550.     move.w        (a3)+,d2
  551. *-------------------------------------------------------*
  552.     lea        (a2,d6.w*4),a6
  553. *-------------------------------------------------------*
  554.     sub.w        d6,d2
  555.     moveq        #4-1,d0
  556.     and.w        d2,d0
  557.     asr.w        #2,d2                ; dx{loop}
  558. *-------------------------------------------------------*
  559.     move.l        d0,d6
  560.     lsl.w        #3,d6
  561.     add.w        d6,d0                ; dx{remainder} * -9
  562.     neg.w        d0
  563. *-------------------------------------------------------*
  564.     move.w        d3,d6
  565.     add.l        d7,d3
  566.     move.w        d6,d3
  567.     moveq        #0,d6
  568. *-------------------------------------------------------*
  569. *    Flat-rendering instruction tower        *
  570. *-------------------------------------------------------*
  571.     jmp        .sdx_j(pc,d0.w*2)        ; index instruction tower
  572. .sdx_l:    srun32
  573.     srun32
  574.     srun32
  575.     srun32
  576. .sdx_j:    dbra        d2,.sdx_l
  577. *-------------------------------------------------------*
  578.     swap        d2
  579.     dbra        d2,.srun_loop
  580. *-------------------------------------------------------*
  581. .snull_line:
  582. *-------------------------------------------------------*
  583.     lea        (max_xres*2)(a2),a2
  584.     addq.l        #1,d1
  585.     swap        d4
  586.     dbra        d4,.sline_loop
  587. *-------------------------------------------------------*
  588.     bra        .zone_loop
  589. *-------------------------------------------------------*
  590. .last_zone:
  591. *-------------------------------------------------------*
  592. .stop:    rts
  593.  
  594. *-------------------------------------------------------*
  595. *    Local variables                    *
  596. *-------------------------------------------------------*
  597. .local_screen:        ds.l    1
  598. *-------------------------------------------------------*
  599.  
  600.     rept        0
  601.  
  602. vrun    macro
  603.     and.w        d5,d4
  604.     move.b        (a2,d4.w),d1
  605.     addx.l        d3,d4
  606.     move.w        (a5,d1.l*2),d0
  607.     adda.l        a6,a0
  608.     move.w        d0,(a0)
  609.     endm
  610.  
  611. *-------------------------------------------------------*
  612. *    Render the walls                *
  613. *-------------------------------------------------------*
  614.     txtlong
  615. *-------------------------------------------------------*
  616. render_walls:
  617. *-------------------------------------------------------*
  618.     rts
  619.     lea        wallruns,a1
  620.     moveq        #0,d6
  621.     move.w        wallruncount,d6
  622.     subq.w        #1,d6
  623.     bmi        .err
  624.     move.l        screen,a4
  625.     moveq        #0,d5
  626.     move.w        scrwidth,d5
  627.     add.l        d5,d5
  628.     move.l        d5,a6
  629.     sub.l        a6,a4
  630.  
  631.     move.w        #128-1,d5
  632.  
  633. ;    i,j1j2,z,u,dv,v
  634.     
  635.     lea        wall_texture,a3
  636. *-------------------------------------------------------*
  637. *    Wall-column horizontal loop            *    
  638. *-------------------------------------------------------*
  639. .runs:    move.w        (a1)+,d3            ; i (screen)
  640.     moveq        #0,d1
  641.     move.b        (a1)+,d1            ; j1 (screen/top)
  642.     moveq        #0,d2
  643.     move.b        (a1)+,d2            ; j2 (screen/bot)
  644.     lea        colourtables,a5
  645.     lea        (a4,d3.w*2),a0            ; address screen (i)
  646.     sub.w        d1,d2                ; dj (height)
  647.     lsl.l        #4,d1
  648.     move.l        d1,d0
  649.     move.w        (a1)+,d4            ; u (texture)
  650.     lsl.l        #2,d1
  651.     add.l        d1,d0
  652.     lsl.l        #3,d0
  653.     move.l        (a1)+,d3            ; dv[i:f] (texture)
  654.     add.l        d0,a0                ; address j (screen)
  655.     moveq        #0,d0
  656.     lea        (a3,d4.w),a2            ; address u (texture)
  657.     moveq        #0,d4
  658.     move.w        (a1)+,d4            ; v (texture)
  659.     move.b        d3,d0                ; luminance
  660.     lsl.l        #8,d0
  661.     add.l        d0,a5                ; address luminance table
  662.     asr.l        #8,d3
  663.     swap        d3
  664.     lsl.l        #8,d4
  665.     swap        d4
  666. *-------------------------------------------------------*
  667. *    Calculate tower index & interations        *
  668. *-------------------------------------------------------*
  669.     moveq        #4-1,d0
  670.     and.w        d2,d0                ; index = remainder(4)
  671.     lsr.w        #2,d2                ; loopsize / 4
  672.     neg.w        d0
  673.     add.w        d0,d0                ; index * -2
  674. *-------------------------------------------------------*
  675. *    Preload carry for cascading adder        *
  676. *-------------------------------------------------------*
  677.     move.w        d4,d1                ; store v[i]
  678.     add.l        d3,d4                ; v[i:f]=v[i:f]+dv[i:f]
  679.     move.w        d1,d4                ; restore v[i]
  680. *-------------------------------------------------------*
  681. *    Execute instruction tower            *
  682. *-------------------------------------------------------*
  683.     clr.l        d1
  684.     jmp        .dx_j(pc,d0.w*8)        ; jump -> index * -16
  685. .dx_l:    vrun
  686.     vrun
  687.     vrun
  688.     vrun
  689. .dx_j:    dbra        d2,.dx_l
  690. *-------------------------------------------------------*
  691. *    Address next wall column            *
  692. *-------------------------------------------------------*
  693.     dbra        d6,.runs
  694. .err:    rts
  695.  
  696.     endr
  697.  
  698. *-------------------------------------------------------*
  699. render_wall:
  700. *-------------------------------------------------------*
  701.     cmp.w        #texcode_none,wall_id
  702.     beq        flush_badwall
  703.     cmp.w        #texcode_sky,wall_id
  704.     beq        flush_badwall
  705. *-------------------------------------------------------*
  706.     tst.b        addwall_opaque(a6)
  707.     bne        stack_transparent
  708. *-------------------------------------------------------*
  709.     moveq        #0,d0
  710.     move.w        wall_id,d0
  711.     bmi.s        .err
  712.     bsr        cache_resource
  713.     move.l        d0,d6
  714. .err:    move.l        screen,a4
  715.     move.w        #128-1,d5
  716.     lea        DSPHost16.w,a1
  717.     lea        DSPHostStat.w,a3
  718. *-------------------------------------------------------*
  719.     tst.b        halfrows
  720.     bne        render_wall_2x1
  721.  
  722. *-------------------------------------------------------*
  723. render_wall_1x1:
  724. *-------------------------------------------------------*
  725.     move.w        scrwidth,a6
  726.     add.l        a6,a6
  727.     sub.l        a6,a4
  728. *-------------------------------------------------------*
  729.     dspwaitread.0    (a3)
  730.     move.w        (a1),d3                ; i (screen)
  731.     bmi        .dsp_done
  732. *-------------------------------------------------------*
  733. .next:    moveq        #0,d1
  734.     dspwaitread.0    (a3)
  735.     move.w        (a1),d1                ; j1j2
  736.     lea        colourtables,a5
  737.     lea        (a4,d3.w*2),a0            ; address screen (i)
  738.     moveq        #0,d2
  739.     move.b        d1,d2                ; j2 (screen/bot)
  740.     lsr.w        #8,d1                ; j1 (screen/top)
  741.     sub.w        d1,d2                ; dj (height)
  742.     lsl.l        #4,d1
  743.     move.l        d1,d0
  744.     dspwaitread.0    (a3)
  745.     move.w        (a1),d4                ; z
  746.     lea        (a5,d4.w*8),a5            ; address luminance table
  747.     moveq        #0,d4
  748.     dspwaitread.3    (a3)
  749.     move.w        (a1),d4                ; u (texture)
  750.     lsl.l        #2,d1
  751.     add.l        d1,d0
  752.     lsl.l        #3,d0
  753.     move.l        d6,a2
  754.     add.l        d4,a2                ; address u (texture)
  755.     dspwaitread.0    (a3)
  756.     move.l        -2(a1),d3            ; dv[i:f] (texture)
  757.     add.l        d0,a0                ; address j (screen)
  758.     moveq        #0,d4
  759.     swap        d3
  760.     ext.w        d3
  761.     dspwaitread.3    (a3)
  762.     move.w        (a1),d4                ; v (texture)
  763. *-------------------------------------------------------*
  764. *    Calculate tower index & interations        *
  765. *-------------------------------------------------------*
  766.     moveq        #4-1,d0
  767.     and.w        d2,d0                ; index = remainder(4)
  768.     lsr.w        #2,d2                ; loopsize / 4
  769.     neg.w        d0
  770.     add.w        d0,d0                ; index * -2
  771. *-------------------------------------------------------*
  772. *    Preload carry for cascading adder        *
  773. *-------------------------------------------------------*
  774.     lsl.l        #8,d4
  775.     swap        d4
  776.     move.w        d4,d1                ; store v[i]
  777.     add.l        d3,d4                ; v[i:f]=v[i:f]+dv[i:f]
  778.     move.w        d1,d4                ; restore v[i]
  779. *-------------------------------------------------------*
  780. *    Execute instruction tower            *
  781. *-------------------------------------------------------*
  782.     clr.l        d1
  783.     jmp        .dx_j(pc,d0.w*8)        ; jump -> index * -16
  784. .dx_l:    vrun16
  785.     vrun16
  786.     vrun16
  787.     vrun16
  788. .dx_j:    dbra        d2,.dx_l
  789. *-------------------------------------------------------*
  790.     dspwaitread.0    (a3)
  791.     move.w        (a1),d3                ; i (screen)
  792.     bpl        .next
  793. *-------------------------------------------------------*
  794. .dsp_done:
  795. *-------------------------------------------------------*
  796.     rts
  797.  
  798. *-------------------------------------------------------*
  799. render_wall_2x1:
  800. *-------------------------------------------------------*
  801.     move.w        scrwidth,a6
  802.     subq.l        #1,a6
  803.     add.l        a6,a6
  804.     sub.l        a6,a4
  805. *-------------------------------------------------------*
  806.     dspwaitread.0    (a3)
  807.     move.w        (a1),d3                ; i (screen)
  808.     bmi        .dsp_done
  809. *-------------------------------------------------------*
  810. .next:    moveq        #0,d1
  811.     dspwaitread.0    (a3)
  812.     move.w        (a1),d1                ; j1j2
  813.     lea        colourtables,a5
  814.     lea        (a4,d3.w*4),a0            ; address screen (i)
  815.     moveq        #0,d2
  816.     move.b        d1,d2                ; j2 (screen/bot)
  817.     lsr.w        #8,d1                ; j1 (screen/top)
  818.     sub.w        d1,d2                ; dj (height)
  819.     lsl.l        #4,d1
  820.     move.l        d1,d0
  821.     dspwaitread.0    (a3)
  822.     move.w        (a1),d4                ; z
  823.     lea        (a5,d4.w*8),a5            ; address luminance table
  824.     moveq        #0,d4
  825.     dspwaitread.3    (a3)
  826.     move.w        (a1),d4                ; u (texture)
  827.     lsl.l        #2,d1
  828.     add.l        d1,d0
  829.     lsl.l        #3,d0
  830.     move.l        d6,a2
  831.     add.l        d4,a2                ; address u (texture)
  832.     dspwaitread.0    (a3)
  833.     move.l        -2(a1),d3            ; dv[i:f] (texture)
  834.     add.l        d0,a0                ; address j (screen)
  835.     moveq        #0,d4
  836.     swap        d3
  837.     ext.w        d3
  838.     dspwaitread.3    (a3)
  839.     move.w        (a1),d4                ; v (texture)
  840. *-------------------------------------------------------*
  841. *    Calculate tower index & interations        *
  842. *-------------------------------------------------------*
  843.     moveq        #4-1,d0
  844.     and.w        d2,d0                ; index = remainder(4)
  845.     lsr.w        #2,d2                ; loopsize / 4
  846.     move.w        d0,d1
  847.     lsl.w        #3,d1
  848.     add.w        d1,d0
  849.     neg.w        d0                ; index * -9
  850. *-------------------------------------------------------*
  851. *    Preload carry for cascading adder        *
  852. *-------------------------------------------------------*
  853.     lsl.l        #8,d4
  854.     swap        d4
  855.     move.w        d4,d1                ; store v[i]
  856.     add.l        d3,d4                ; v[i:f]=v[i:f]+dv[i:f]
  857.     move.w        d1,d4                ; restore v[i]
  858. *-------------------------------------------------------*
  859. *    Execute instruction tower            *
  860. *-------------------------------------------------------*
  861.     clr.l        d1
  862.     jmp        .dx_j(pc,d0.w*2)        ; jump -> index * -16
  863. .dx_l:    vrun32
  864.     vrun32
  865.     vrun32
  866.     vrun32
  867. .dx_j:    dbra        d2,.dx_l
  868. *-------------------------------------------------------*
  869.     dspwaitread.0    (a3)
  870.     move.w        (a1),d3                ; i (screen)
  871.     bpl        .next
  872. *-------------------------------------------------------*
  873. .dsp_done:
  874. *-------------------------------------------------------*
  875.     rts
  876.  
  877. *-------------------------------------------------------*
  878. render_transparent:
  879. *-------------------------------------------------------*
  880.     
  881.     move.l        screen,a4
  882.     move.w        #128-1,d5
  883.  
  884.     tst.b        halfrows
  885.     bne        render_transparent_2x1
  886.  
  887. *-------------------------------------------------------*
  888. render_transparent_1x1:
  889. *-------------------------------------------------------*
  890.     move.w        scrwidth,a6
  891.     add.l        a6,a6
  892. *-------------------------------------------------------*
  893.     move.l        transparent_array,a3
  894.     move.w        transparent_count,d7
  895.     subq.w        #1,d7
  896.     bmi        .err
  897. *-------------------------------------------------------*
  898. .wall_loop:
  899. *-------------------------------------------------------*
  900.     swap        d7
  901.     move.w        -(a3),d7
  902. *-------------------------------------------------------*
  903. *    Case #1 - masked transparent            *
  904. *-------------------------------------------------------*
  905.     moveq        #0,d0
  906.     move.w        -(a3),d0
  907.     bpl.s        .masked_transparent
  908. *-------------------------------------------------------*
  909. *    Case #2 - alpha transparent            *
  910. *-------------------------------------------------------*
  911.     cmp.w        #texcode_qalpha,d0
  912.     bra        .alpha_transparent
  913. *-------------------------------------------------------*
  914. *    Case #3 - invalid transparent            *
  915. *-------------------------------------------------------*
  916.     bra        .skip_wall
  917. *-------------------------------------------------------*
  918. .masked_transparent:
  919. *-------------------------------------------------------*
  920.     bsr        cache_resource
  921.     move.l        d0,d6
  922. *-------------------------------------------------------*
  923. .column_loop:
  924. *-------------------------------------------------------*
  925.     lea        -14(a3),a3
  926.     move.l        a3,a1
  927.     move.w        (a1)+,d3            ; i (screen)
  928.     moveq        #0,d1
  929.     move.w        (a1)+,d1            ; j1j2
  930.     lea        colourtables,a5
  931.     lea        (a4,d3.w*2),a0            ; address screen (i)
  932.     moveq        #0,d2
  933.     move.b        d1,d2                ; j2 (screen/bot)
  934.     lsr.w        #8,d1                ; j1 (screen/top)
  935.     sub.w        d1,d2                ; dj (height)
  936.     lsl.l        #4,d1
  937.     move.l        d1,d0
  938.     move.w        (a1)+,d4            ; z
  939.     lea        (a5,d4.w*8),a5            ; address luminance table
  940.     moveq        #0,d4
  941.     move.w        (a1)+,d4            ; u (texture)
  942.     lsl.l        #2,d1
  943.     add.l        d1,d0
  944.     lsl.l        #3,d0
  945.     move.l        d6,a2
  946.     add.l        d4,a2                ; address u (texture)
  947.     move.l        (a1)+,d3            ; dv[i:f] (texture)
  948.     add.l        d0,a0                ; address j (screen)
  949.     moveq        #0,d4
  950.     swap        d3
  951.     ext.w        d3
  952.     move.w        (a1)+,d4            ; v (texture)
  953. *-------------------------------------------------------*
  954. *    Calculate tower index & interations        *
  955. *-------------------------------------------------------*
  956.     moveq        #4-1,d0
  957.     and.w        d2,d0                ; index = remainder(4)
  958.     lsr.w        #2,d2                ; loopsize / 4
  959.     add.w        d0,d0
  960.     neg.w        d0                ; index * -2
  961. *-------------------------------------------------------*
  962. *    Preload carry for cascading adder        *
  963. *-------------------------------------------------------*
  964.     lsl.l        #8,d4
  965.     swap        d4
  966.     move.w        d4,d1                ; store v[i]
  967.     add.l        d3,d4                ; v[i:f]=v[i:f]+dv[i:f]
  968.     move.w        d1,d4                ; restore v[i]
  969. *-------------------------------------------------------*
  970. *    Execute instruction tower            *
  971. *-------------------------------------------------------*
  972.     clr.l        d1
  973.     jmp        .dx_j(pc,d0.w*8)        ; jump -> index * -16
  974. .dx_l:    tvrun16
  975.     tvrun16
  976.     tvrun16
  977.     tvrun16
  978. .dx_j:    dbra        d2,.dx_l
  979. *-------------------------------------------------------*
  980.     dbra        d7,.column_loop
  981. *-------------------------------------------------------*
  982. .skip_wall:
  983. *-------------------------------------------------------*
  984.     swap        d7
  985.     dbra        d7,.wall_loop
  986. .err:    rts
  987.  
  988. *-------------------------------------------------------*
  989. .alpha_transparent:
  990. *-------------------------------------------------------*
  991.     lea        quick_alpha_table,a5
  992. *-------------------------------------------------------*
  993. .acolumn_loop:
  994. *-------------------------------------------------------*
  995.     lea        -14(a3),a3
  996.     move.l        a3,a1
  997.     move.w        (a1)+,d3            ; i (screen)
  998.     moveq        #0,d1
  999.     move.w        (a1)+,d1            ; j1j2
  1000.     lea        (a4,d3.w*2),a0            ; address screen (i)
  1001.     moveq        #0,d2
  1002.     move.b        d1,d2                ; j2 (screen/bot)
  1003.     lsr.w        #8,d1                ; j1 (screen/top)
  1004.     sub.w        d1,d2                ; dj (height)
  1005.     lsl.l        #4,d1
  1006.     move.l        d1,d0
  1007.     lsl.l        #2,d1
  1008.     add.l        d1,d0
  1009.     lsl.l        #3,d0
  1010.     add.l        d0,a0                ; address j (screen)
  1011. *-------------------------------------------------------*
  1012. *    Calculate tower index & interations        *
  1013. *-------------------------------------------------------*
  1014.     moveq        #4-1,d0
  1015.     and.w        d2,d0                ; index = remainder(4)
  1016.     lsr.w        #2,d2                ; loopsize / 4
  1017.  
  1018.     move.w        d0,d1
  1019.     add.w        d1,d1
  1020.     sub.w        d1,d0
  1021.     add.w        d1,d1
  1022.     sub.w        d1,d0                ; index * -5
  1023.     
  1024. ;    neg.w        d0                ; index * -1
  1025.  
  1026. *-------------------------------------------------------*
  1027. *    Execute instruction tower            *
  1028. *-------------------------------------------------------*
  1029.     sub.l        a6,a0
  1030.     clr.l        d1
  1031.     jmp        .adx_j(pc,d0.w*2)        ; jump -> index * -10
  1032. .adx_l:    avrun16
  1033.     avrun16
  1034.     avrun16
  1035.     avrun16
  1036. .adx_j:    dbra        d2,.adx_l
  1037. *-------------------------------------------------------*
  1038.     dbra        d7,.acolumn_loop
  1039. *-------------------------------------------------------*
  1040.     swap        d7
  1041.     dbra        d7,.wall_loop
  1042.     rts
  1043.  
  1044. *-------------------------------------------------------*
  1045. render_transparent_2x1:
  1046. *-------------------------------------------------------*
  1047.     move.w        scrwidth,a6
  1048.     add.l        a6,a6
  1049. *-------------------------------------------------------*
  1050.     move.l        transparent_array,a3
  1051.     move.w        transparent_count,d7
  1052.     subq.w        #1,d7
  1053.     bmi        .err
  1054. *-------------------------------------------------------*
  1055. .wall_loop:
  1056. *-------------------------------------------------------*
  1057.     swap        d7
  1058.     move.w        -(a3),d7
  1059. *-------------------------------------------------------*
  1060. *    Case #1 - masked transparent            *
  1061. *-------------------------------------------------------*
  1062.     moveq        #0,d0
  1063.     move.w        -(a3),d0
  1064.     bpl.s        .masked_transparent
  1065. *-------------------------------------------------------*
  1066. *    Case #2 - alpha transparent            *
  1067. *-------------------------------------------------------*
  1068.     cmp.w        #texcode_qalpha,d0
  1069.     beq        .alpha_transparent
  1070. *-------------------------------------------------------*
  1071. *    Case #3 - invalid transparent            *
  1072. *-------------------------------------------------------*
  1073.     bra        .skip_wall
  1074. *-------------------------------------------------------*
  1075. .masked_transparent:
  1076. *-------------------------------------------------------*
  1077.     bsr        cache_resource
  1078.     move.l        d0,d6
  1079. *-------------------------------------------------------*
  1080. .column_loop:
  1081. *-------------------------------------------------------*
  1082.     lea        -14(a3),a3
  1083.     move.l        a3,a1
  1084.     move.w        (a1)+,d3            ; i (screen)
  1085.     moveq        #0,d1
  1086.     move.w        (a1)+,d1            ; j1j2
  1087.     lea        colourtables,a5
  1088.     lea        (a4,d3.w*4),a0            ; address screen (i)
  1089.     moveq        #0,d2
  1090.     move.b        d1,d2                ; j2 (screen/bot)
  1091.     lsr.w        #8,d1                ; j1 (screen/top)
  1092.     sub.w        d1,d2                ; dj (height)
  1093.     lsl.l        #4,d1
  1094.     move.l        d1,d0
  1095.     move.w        (a1)+,d4            ; z
  1096.     lea        (a5,d4.w*8),a5            ; address luminance table
  1097.     moveq        #0,d4
  1098.     move.w        (a1)+,d4            ; u (texture)
  1099.     lsl.l        #2,d1
  1100.     add.l        d1,d0
  1101.     lsl.l        #3,d0
  1102.     move.l        d6,a2
  1103.     add.l        d4,a2                ; address u (texture)
  1104.     move.l        (a1)+,d3            ; dv[i:f] (texture)
  1105.     add.l        d0,a0                ; address j (screen)
  1106.     moveq        #0,d0
  1107.     moveq        #0,d4
  1108.     swap        d3
  1109.     ext.w        d3
  1110.     move.w        (a1)+,d4            ; v (texture)
  1111. *-------------------------------------------------------*
  1112. *    Calculate tower index & interations        *
  1113. *-------------------------------------------------------*
  1114.     moveq        #4-1,d0
  1115.     and.w        d2,d0                ; index = remainder(4)
  1116.     lsr.w        #2,d2                ; loopsize / 4
  1117.     move.w        d0,d1
  1118.     add.w        d1,d1
  1119.     add.w        d1,d0
  1120.     lsl.w        #2,d1
  1121.     add.w        d1,d0
  1122.     neg.w        d0                ; index * -11
  1123. *-------------------------------------------------------*
  1124. *    Preload carry for cascading adder        *
  1125. *-------------------------------------------------------*
  1126.     lsl.l        #8,d4
  1127.     swap        d4
  1128.     move.w        d4,d1                ; store v[i]
  1129.     add.l        d3,d4                ; v[i:f]=v[i:f]+dv[i:f]
  1130.     move.w        d1,d4                ; restore v[i]
  1131. *-------------------------------------------------------*
  1132. *    Execute instruction tower            *
  1133. *-------------------------------------------------------*
  1134.     clr.l        d1
  1135.     jmp        .dx_j(pc,d0.w*2)        ; jump -> index * -22
  1136. .dx_l:    tvrun32
  1137.     tvrun32
  1138.     tvrun32
  1139.     tvrun32
  1140. .dx_j:    dbra        d2,.dx_l
  1141. *-------------------------------------------------------*
  1142.     dbra        d7,.column_loop
  1143. *-------------------------------------------------------*
  1144. .skip_wall:
  1145. *-------------------------------------------------------*
  1146.     swap        d7
  1147.     dbra        d7,.wall_loop
  1148. .err:    rts
  1149.  
  1150. *-------------------------------------------------------*
  1151. .alpha_transparent:
  1152. *-------------------------------------------------------*
  1153.     lea        quick_alpha_table,a5
  1154.     subq.l        #2*2,a6
  1155. *-------------------------------------------------------*
  1156. .acolumn_loop:
  1157. *-------------------------------------------------------*
  1158.     lea        -14(a3),a3
  1159.     move.l        a3,a1
  1160.     move.w        (a1)+,d3            ; i (screen)
  1161.     moveq        #0,d1
  1162.     move.w        (a1)+,d1            ; j1j2
  1163.     lea        (a4,d3.w*4),a0            ; address screen (i)
  1164.     moveq        #0,d2
  1165.     move.b        d1,d2                ; j2 (screen/bot)
  1166.     lsr.w        #8,d1                ; j1 (screen/top)
  1167.     sub.w        d1,d2                ; dj (height)
  1168.     lsl.l        #4,d1
  1169.     move.l        d1,d0
  1170.     lsl.l        #2,d1
  1171.     add.l        d1,d0
  1172.     lsl.l        #3,d0
  1173.     add.l        d0,a0                ; address j (screen)
  1174. *-------------------------------------------------------*
  1175. *    Calculate tower index & interations        *
  1176. *-------------------------------------------------------*
  1177.     moveq        #4-1,d0
  1178.     and.w        d2,d0                ; index = remainder(4)
  1179.     lsr.w        #2,d2                ; loopsize / 4
  1180.     move.w        d0,d1
  1181.     lsl.w        #3,d1
  1182.     sub.w        d1,d0                ; index * -7
  1183. *-------------------------------------------------------*
  1184. *    Execute instruction tower            *
  1185. *-------------------------------------------------------*
  1186.     clr.l        d1
  1187.     sub.l        a6,a0
  1188.     jmp        .adx_j(pc,d0.w*2)        ; jump -> index * -14
  1189. .adx_l:    avrun32
  1190.     avrun32
  1191.     avrun32
  1192.     avrun32
  1193. .adx_j:    dbra        d2,.adx_l
  1194. *-------------------------------------------------------*
  1195.     dbra        d7,.acolumn_loop
  1196. *-------------------------------------------------------*
  1197.     addq.l        #2*2,a6
  1198.     swap        d7
  1199.     dbra        d7,.wall_loop
  1200.     rts
  1201.  
  1202. *-------------------------------------------------------*
  1203. *    Draw composite texture to the screen        *
  1204. *-------------------------------------------------------*
  1205. render_texture:
  1206. *-------------------------------------------------------*
  1207.     bsr        clear_patchtags
  1208.     bsr        load_patches
  1209.     bsr        add_patches
  1210.     rts
  1211.     
  1212. *-------------------------------------------------------*
  1213. *    Load all unique patches into temp buffer    *
  1214. *-------------------------------------------------------*
  1215. load_patches:
  1216. *-------------------------------------------------------*
  1217.     pushall
  1218. ;    move.l        texturelist_array,a0
  1219.     move.l        graphics_array,a0
  1220.     move.l        (a0,d0.w*4),a0
  1221.     move.w        tex_width(a0),patch_xclip
  1222.     move.w        tex_height(a0),patch_yclip
  1223.     move.w        tex_patches(a0),d6
  1224.     lea        tex_len(a0),a0
  1225.     bra.s        .go
  1226. .all:    move.w        texp_index(a0),d0
  1227.     lea        patch_taglist,a1
  1228.     move.w        patch_tags,d1
  1229.     bra.s        .tgo
  1230. .tlp:    cmp.w        (a1),d0
  1231.     beq.s        .old
  1232.     addq.l        #6,a1
  1233. .tgo:    dbra        d1,.tlp
  1234.     addq.w        #1,patch_tags
  1235.     move.w        d0,(a1)+
  1236.     move.l        patchbuffer_ptr,(a1)+
  1237.     pushall
  1238.     move.l        pnamelist_array,a2
  1239.     move.l        (a2,d0.w*4),d1
  1240.     beq        .skip
  1241.     move.l        d1,a0
  1242.     move.l        patchbuffer_ptr,a1
  1243.     move.l        wd_size(a0),d1
  1244.     add.l        d1,patchbuffer_ptr
  1245.     bsr        read_resource
  1246. .skip:    popall
  1247. .old:    lea        texp_len(a0),a0
  1248. .go:    dbra        d6,.all
  1249.     popall
  1250.     rts
  1251.  
  1252. *-------------------------------------------------------*
  1253. *    Prepare to load unique patches using tags    *
  1254. *-------------------------------------------------------*
  1255. clear_patchtags:
  1256. *-------------------------------------------------------*
  1257.     clr.w        patch_tags
  1258.     move.l        #buffer_space,patchbuffer_ptr
  1259.     move.w        #max_patches,d1
  1260.     lea        patch_taglist,a1
  1261.     bra.s        .fgo
  1262. .flp:    move.w        #terminator,(a1)+
  1263.     addq.l        #4,a1
  1264. .fgo:    dbra        d1,.flp
  1265.     rts
  1266.     
  1267. *-------------------------------------------------------*
  1268. *    Build texture up from patches            *
  1269. *-------------------------------------------------------*
  1270. add_patches:
  1271. *-------------------------------------------------------*
  1272.     pushall
  1273.     move.l        graphics_array,a0
  1274. ;    move.l        texturelist_array,a0
  1275.     move.l        (a0,d0.w*4),a0
  1276.     move.w        tex_width(a0),patch_xclip
  1277.     move.w        tex_height(a0),patch_yclip
  1278.     move.w        tex_patches(a0),d6
  1279.     lea        tex_len(a0),a0
  1280.     bra.s        .go
  1281. .all:    move.w        texp_xoff(a0),patch_xoff
  1282.     move.w        texp_yoff(a0),patch_yoff
  1283.     move.w        texp_index(a0),patch_index
  1284.     push.w        d6
  1285.     push.l        a0
  1286.     bsr        render_patch_tex
  1287.     pop.l        a0
  1288.     pop.w        d6
  1289.     lea        texp_len(a0),a0
  1290. .go:    dbra        d6,.all
  1291.     popall
  1292.     rts
  1293.  
  1294. *-------------------------------------------------------*
  1295. *    Draw one patch as a section of a texture    *
  1296. *-------------------------------------------------------*
  1297. render_patch:
  1298. *-------------------------------------------------------*
  1299.     move.w        patch_index,d0
  1300.     move.w        patch_tags,d1
  1301.     lea        patch_taglist,a1
  1302.     bra.s        .fgo
  1303. .flp:    cmp.w        (a1),d0
  1304.     beq.s        .got
  1305.     addq.l        #6,a1
  1306. .fgo:    dbra        d1,.flp
  1307.     bra        .err
  1308. .got:    addq.l        #2,a1
  1309.     move.l        (a1)+,a0
  1310.     move.l        ScreenPhy,a3
  1311.     lea        colourtables+(63*512),a5
  1312.     move.l        a0,a1
  1313.     imov.w        (a0)+,d6            ; width
  1314.     imov.w        (a0)+,d7            ; height
  1315.     imov.w        (a0)+,d0            ; xoff
  1316.     imov.w        (a0)+,d1            ; yoff
  1317.     move.w        patch_yclip,d5
  1318.     move.w        patch_yoff,d1
  1319.     move.w        patch_xoff,d0
  1320.     bpl.s        .xok
  1321.     add.w        d0,d6
  1322.     ble        .err
  1323.     neg.w        d0
  1324.     lea        (a0,d0.w*4),a0
  1325.     moveq        #0,d0
  1326. .xok:    lea        (a3,d0.w*2),a3
  1327.     add.w        d6,d0
  1328.     sub.w        patch_xclip,d0
  1329.     ble.s        .go
  1330.     sub.w        d0,d6
  1331.     ble        .err
  1332.     bra.s        .go
  1333. .col:    imov.l        (a0)+,a2
  1334.     add.l        a1,a2                ; post data
  1335. .next:    moveq        #0,d0
  1336.     move.b        (a2)+,d0
  1337.     cmp.b        #255,d0
  1338.     beq.s        .stop
  1339.     move.w        d1,d2                ; base y-offset
  1340.     add.w        d0,d2                ; post y-offset
  1341.     move.w        d2,d3
  1342.     muls.w        #(max_xres*2),d3
  1343.     lea        (a3,d3.l),a4
  1344.     moveq        #0,d0
  1345.     move.b        (a2)+,d0            ; post length
  1346.     moveq        #0,d3
  1347.     addq.l        #1,a2
  1348.     bra.s        .vgo
  1349. .vert:    move.b        (a2)+,d3
  1350.     tst.w        d2
  1351.     bmi.s        .skip
  1352.     cmp.w        d5,d2
  1353.     bpl.s        .skip
  1354.     move.w        (a5,d3.w*2),(a4)
  1355. .skip:    addq.w        #1,d2
  1356.     lea        (max_xres*2)(a4),a4
  1357. .vgo:    dbra        d0,.vert
  1358.     addq.l        #1,a2
  1359.     bra.s        .next
  1360. .stop:    addq.l        #2,a3
  1361. .go:    dbra        d6,.col
  1362. .err:    rts
  1363.  
  1364. *-------------------------------------------------------*
  1365. *    Draw one patch as a section of a texture    *
  1366. *-------------------------------------------------------*
  1367. render_patch_tex:
  1368. *-------------------------------------------------------*
  1369.     move.w        patch_index,d0
  1370.     move.w        patch_tags,d1
  1371.     lea        patch_taglist,a1
  1372.     bra.s        .fgo
  1373. .flp:    cmp.w        (a1),d0
  1374.     beq.s        .got
  1375.     addq.l        #6,a1
  1376. .fgo:    dbra        d1,.flp
  1377.     bra        .err
  1378. .got:    addq.l        #2,a1
  1379.     move.l        (a1)+,a0
  1380.     move.l        texture_ptr,a3
  1381.     move.l        a0,a1
  1382.     imov.w        (a0)+,d6            ; width
  1383.     imov.w        (a0)+,d7            ; height
  1384.     imov.w        (a0)+,d0            ; xoff
  1385.     imov.w        (a0)+,d1            ; yoff
  1386.     move.w        black,d7
  1387.     move.w        patch_yclip,d5
  1388.     move.w        patch_yoff,d1
  1389.     move.w        patch_xoff,d0
  1390.     bpl.s        .xok
  1391.     add.w        d0,d6
  1392.     ble        .err
  1393.     neg.w        d0
  1394.     lea        (a0,d0.w*4),a0
  1395.     moveq        #0,d0
  1396. .xok:    move.w        d0,d3
  1397.     mulu.w        patch_yclip,d3
  1398.     add.l        d3,a3
  1399.     add.w        d6,d0
  1400.     sub.w        patch_xclip,d0
  1401.     ble.s        .go
  1402.     sub.w        d0,d6
  1403.     ble        .err
  1404.     bra.s        .go
  1405. .col:    imov.l        (a0)+,a2
  1406.     add.l        a1,a2                ; post data
  1407. .next:    moveq        #0,d0
  1408.     move.b        (a2)+,d0
  1409.     cmp.b        #255,d0
  1410.     beq.s        .stop
  1411.     move.w        d1,d2                ; base y-offset
  1412.     add.w        d0,d2                ; post y-offset
  1413.     move.w        d2,d3
  1414.     lea        (a3,d3.w),a4
  1415.     moveq        #0,d0
  1416.     move.b        (a2)+,d0            ; post length
  1417.     moveq        #0,d3
  1418.     addq.l        #1,a2
  1419.     bra.s        .vgo
  1420. .vert:    tst.w        d2
  1421.     bmi.s        .skip
  1422.     cmp.w        d5,d2
  1423.     bpl.s        .skip
  1424.     move.b        (a2),d3
  1425.     bne.s        .nz
  1426.     move.b        d7,d3
  1427. .nz:    move.b        d3,(a4)
  1428. .skip:    addq.l        #1,a2
  1429.     addq.w        #1,d2
  1430.     addq.l        #1,a4
  1431. .vgo:    dbra        d0,.vert
  1432.     addq.l        #1,a2
  1433.     bra.s        .next
  1434. .stop:    add.w        patch_yclip,a3
  1435. .go:    dbra        d6,.col
  1436. .err:    rts
  1437.  
  1438. xoff:            ds.l    1
  1439. skyx:            ds.l    1
  1440. skyy:            ds.l    1
  1441.     
  1442. texture_ptr:        ds.l    1
  1443.  
  1444. *-------------------------------------------------------*
  1445.             datlong
  1446. *-------------------------------------------------------*
  1447.  
  1448. wall_texture_file:    ;incbin    data\wall8bit.apx
  1449. wall_texture:    =    wall_texture_file+20+768
  1450.  
  1451. *-------------------------------------------------------*
  1452.             bsslong
  1453. *-------------------------------------------------------*
  1454.  
  1455. patchbuffer_ptr:    ds.l    1
  1456.  
  1457. colourtables:        ds.w    256*64            ; space for 64 light levels of palette
  1458. quick_alpha_table:    ds.w    65536            ; space for quick-alpha indexes
  1459.  
  1460. patch_xclip:        ds.w    1            ; patch dimensions & clipping rectangle
  1461. patch_yclip:        ds.w    1
  1462. patch_xoff:        ds.w    1
  1463. patch_yoff:        ds.w    1
  1464. patch_index:        ds.w    1
  1465. patch_tags:        ds.w    1
  1466.  
  1467. patch_taglist:        ds.b    (2+4)*max_patches    ; space for list of unique patch tags
  1468. buffer_space:        ds.b    65536            ; space for all patches in texture
  1469.  
  1470. final_flat:        ds.b    1            ; flag for last texture run
  1471.  
  1472. *-------------------------------------------------------*
  1473.             txtlong
  1474. *-------------------------------------------------------*
  1475.